[1] 12
GVPT399F: Power, Politics, and Data
Learn basic operations in R
Be introduced to dplyr
Clean up and transform your data
Create new objects with <-
Many functions come with R straight out of the box:
You can create objects using functions:
First, you need to install the gapminder package:
Then access the gapminder data set:
# A tibble: 6 × 6
country continent year lifeExp pop gdpPercap
<fct> <fct> <int> <dbl> <int> <dbl>
1 Afghanistan Asia 1952 28.8 8425333 779.
2 Afghanistan Asia 1957 30.3 9240934 821.
3 Afghanistan Asia 1962 32.0 10267083 853.
4 Afghanistan Asia 1967 34.0 11537966 836.
5 Afghanistan Asia 1972 36.1 13079460 740.
6 Afghanistan Asia 1977 38.4 14880372 786.
In gapminder:
fctr stands for factors, which R uses to represent categorical variables with fixed possible values.
int stands for integer.
dbl stands for doubles (or real numbers).
Other types:
chr stands for character vectors, or strings.
dttm stands for date-times (a date + a time).
lgl stands for logical, vectors that contain only TRUE or FALSE.1
dplyrHelp you with most of your data transformation needs.
Five basic functions:
filter()
arrange()
select()
mutate()
summarise()